<template>
	<view>
		<block v-if=" userInfo.intendedschoolname == '' &&  userInfo.intendedmajor == ''">
			<view class="wm">	
				<view class="form">
					<uni-forms ref="form" :modelValue="FormData" :rules="rules">
						<!-- 毕业学校 -->
						<uni-forms-item label="毕业学校:" name="schoolname" labelWidth="100" required :label-width="labW" label-align="right">
							<uni-easyinput type="text" v-model="FormData.schoolname" placeholder="请填写毕业学校名称"></uni-easyinput>
						</uni-forms-item>
						<!-- 毕业专业 -->
						<uni-forms-item label="毕业类别:" name="major" labelWidth="100" required :label-width="labW" label-align="right">
							<uni-data-picker placeholder="请选择毕业类别" v-model="classes" popup-title="请选择意向专业" :localdata="dataTree"
								@change="onchange" @nodeclick="onnodeclick" @popupopened="onpopupopened" @popupclosed="onpopupclosed">
							</uni-data-picker>
						</uni-forms-item>
						<!-- 意向学校 -->
						<uni-forms-item label="意向学校:" name="intendedschoolname" labelWidth="100"  :label-width="labW" label-align="right">
							<uni-easyinput type="text" v-model="FormData.intendedschoolname" placeholder="请选择意向学校"></uni-easyinput>
						</uni-forms-item>
						<!-- 意向专业 -->
						<uni-forms-item label="意向专业:" name="intendedmajor" labelWidth="100"  :label-width="labW" label-align="right">
							<uni-easyinput type="text" v-model="FormData.intendedmajor" placeholder="请选择意向专业"></uni-easyinput>
						</uni-forms-item>
						
						<button  @click="save" class="savebtn">保存</button>
					</uni-forms>
				</view>
			</view>
		</block>
		<block v-else>
			<!-- 图片 -->
			<uni-notice-bar show-icon scrollable text="七分考三份报，志愿填报很重要" />
			<view class="banner">
				<image  src="../../static/zs.jpg" class="banner_image"></image>
			</view>
			<view class="text_1">一对一负责老师微信二维码</view>
			<view class="qrcode">
				<image :src="portImageUrl +'userteahcerqrcode/'+ this.teacherInfo.qrcode" class="qrcode_image" :show-menu-by-longpress='true'></image>
				
			</view>
			<view class="text">
				<view @click="telphone">
					<uni-icons type="phone-filled" color="#e37c32"></uni-icons>
					{{this.teacherInfo.name}} : {{this.teacherInfo.phone}}
				</view>
			</view>
			<view class="tip_text">
				<uni-icons type="star-filled" color="#f00"></uni-icons>
			    请尽快与指导老师联系领取单招报考方案
				<uni-icons type="star-filled" color="#f00"></uni-icons>
			</view>
			
		</block>
	</view>
</template>

<script>
	import {mapState,mapMutations} from "vuex"
	export default {
		name:"aspiration",
		data() {
			return {
				labW:"150rpx",
				classes:"",
				//倒计时时间
				seconds:"",
				time:null, //计时器
				FormData:{
					schoolname:"",//毕业学校
					major:"", //毕业专业
					intendedschoolname:"", //意向学校
					intendedmajor:"", //意向专业
				},
				//表单验证
				rules:{
					//毕业学校
					schoolname:{
						rules:[
							{
								required:true,
								errorMessage:"请输入毕业学校"
							}
						]
					},
					//毕业大类
					major:{
						rules:[
							{
								required:true,
								errorMessage:"请输入毕业大类"
							}
						]
					},
				},
				//毕业类别数据集合
				dataTree: [],
				// dataTree: [{
				// 		text: "一年级",
				// 		value: "1-0",
				// 		children: [{
				// 			text: "1.1班",
				// 			value: "1-1"
				// 		},
				// 		{
				// 			text: "1.2班",
				// 			value: "1-2"
				// 		}]
				// 	},
				// 	{
				// 		text: "二年级",
				// 		value: "2-0",
				// 		children: [{
				// 			text: "2.1班",
				// 			value: "2-1"
				// 		},
				// 		{
				// 			text: "2.2班",
				// 			value: "2-2"
				// 		}]
				// 	},
				// 	{
				// 		text: "三年级",
				// 		value: "3-0",
				// 		disable: true
				// 	}]
				// }
				checkinvitationcode:"",
				portImageUrl: getApp().globalData.portImageUrl
			}
		},
		computed:{
			...mapState("m_user",["userInfo","token","redirectInfo","teacherInfo"]),
		},
		onReady(){
			if(this.userInfo.intendedschoolname == '' &&  this.userInfo.intendedmajor == ''){
				this.$refs.form.setRules(this.rules);
			}
		},
		onShow(){
			
		},
		methods: {
			...mapMutations("m_user",['updateUserInfo',"updateToken","updateRedirectInfo"]),
		
			/**
			 * 初始化数据
			 */
			async getQuestionType(){
				const {data:res} = await uni.$http.post("Schools/getQuestionType");
				this.dataTree = res.data;
			},
			/**
			 * 保存
			 */
			async save(){
				this.$refs.form.validate().then(async (res) => {
					//判断是否登录
					if(!this.token){
					   this.delayNavigate("登录后再填报志愿！",3,"登录页","/pages/my/my","switchTab")
					   return
					}
					//判断是否是VIP页面
					if(this.userInfo.vip == 0){
					    this.delayNavigate("开通会员后再填报！",3,"开通会员页","/subpkg/vip_page/vip_page","navigate")
						return
					}
					uni.showLoading()
					//组织要修改的数据
					let $query = {
						"id":this.userInfo.id,
						"token":this.userInfo.token,
						"schoolname":this.FormData.schoolname,
						"major":this.FormData.major,
						"intendedmajor": this.FormData.intendedmajor,
						"intendedschoolname":  this.FormData.intendedschoolname,
					}
					//请求数据接口修改数据
					const {data:result} = await uni.$http.post("Users/updateUserInfo",$query)
					if(result.meta.status == 0) return uni.$showMsg(result.meta.msg);
					result.data['token'] = this.userInfo.token
					//修改成功之后更新storage中的用户信息
					this.updateUserInfo(result.data.userinfo);
					uni.hideLoading()
					uni.$showMsg("志愿填报成功");
					//返回管理页面
					// setTimeout(()=>{
					// 	uni.switchTab({
					// 		url:"/pages/home/home"
					// 	})
					// },1500);
				}).catch(err => {
					uni.hideLoading()
					uni.$showMsg(err[0].errorMessage);
				})
			},
			/**
			 * 跳转的提示信息框
			 * @param {Object} msg 提示信息前半段
			 * @param {Object} s   秒
			 * @param {Object} pageName 跳转到的页面名称
			 */
			async showTips(msg,s,pageName){
				await uni.showToast({
					icon:"none",
					title:msg+s+"秒后自动跳转到"+pageName,
					mask:true,
					duration:1000,
				})
			},
			/**
			 * 倒计时跳转
			 * @param {Object} msg  跳转的提示信息前半段
			 * @param {Object} second 跳转倒计时时间 
			 * @param {Object} pageName 跳转到的页面名称
			 * @param {Object} pageurl 跳转到的页面地址
			 */
			delayNavigate(msg,second,pageName,pageurl,opentype){
				this.seconds = second
				this.showTips(msg,this.seconds,pageName);
				this.time = setInterval(()=>{
					this.seconds--
					//判断当前时间是否已经到了
					if(this.seconds <= 0){
						clearInterval(this.time);
						//打开方式
						if(opentype == "switchTab"){
							uni.switchTab({
								url:pageurl,
								success:()=>{
									//跳转成功后再vuex中保存要返回的地址和返回的方式
									this.updateRedirectInfo({
										openType:"switchTab", 
										from:"/pages/zytb/zytb"
									})
								}
							})
							return
						}else if(opentype = "navigate"){
							uni.navigateTo({
								url:pageurl,
								success:()=>{
									//跳转成功后再vuex中保存要返回的地址和返回的方式
									this.updateRedirectInfo({
										openType:"switchTab", 
										from:"/pages/zytb/zytb"
									})
								}
							})
							return
						}
						
					}
					this.showTips(msg,this.seconds,pageName)
				},1000)
			},
			/**
			 * 点击拨打电话
			 */
			telphone(){
				uni.makePhoneCall({
					phoneNumber:this.teacherInfo.phone
				})
			},
			//
			onnodeclick(e) {
				// console.log(e);
			},
			onpopupopened(e) {
				//获取专业大类列表
				this.getQuestionType()
				// console.log('popupopened');
				
			},
			onpopupclosed(e) {
			},
			onchange(e) {
				if(typeof e.detail.value[0] !== "undefined"){
					this.FormData.major = e.detail.value[0]["text"]
				}
			}
			//--
		}
		
	}
</script>

<style lang="scss">
.container{
	padding-bottom:50rpx;
}
.tips{
	text-align:center;
	font-size:25rpx;
	color:#ff7d5d;
	padding:25rpx;
	padding-bottom:0rpx;
}
.form{
	background-color:#fff;
	margin:30rpx 0 50rpx 0;
	padding:20rpx;
	border-radius: 15rpx;
}
.savebtn{
	background:linear-gradient(to  right,#93bdf3,#68d0e3);
	color:#fff;
	height: 35px;
	border:0;
	line-height: 35px;
	&:active{
		background:linear-gradient(to  right,#8ab3e4,#62c4d5);
	}
}

.title{
	font-size: 14px;
	font-weight: bold;
	margin: 20px 0 5px 0;
}

.data-pickerview{
	height: 400px;
	border: 1px #e5e5e5 solid;
}

.popper__arrow{
    top: -6px;
    left: 50%;
    margin-right: 3px;
    border-top-width: 0;
    border-bottom-color: #EBEEF5;
}
 .popper__arrow{
    top: -6px;
    left: 50%;
    margin-right: 3px;
    border-top-width: 0;
    border-bottom-color: #EBEEF5;
}
/*联系老师*/
.banner{
   width:100%;
   height: 420rpx;
   overflow: hidden;
   .banner_image{
	   width: 100%;
	   height: 100%;
   }
}
.qrcode{
	width:400rpx;
	height:400rpx;
	margin:10rpx auto;
	.qrcode_image{
		width: 100%;
		height: 100%;
	}
	
}
.text_1{
	margin-top:30rpx;
	color:#5c5c5c;
	font-size:30rpx;
	height:50rpx;
	line-height: 50rpx;	
    text-align: center;
	color:#e37c32
}
.text{
	color:#4c4c4c;
	height:50rpx;
	font-size:30rpx;
	line-height: 50rpx;	
    text-align: center;
	color:#e37c32
}
.tip_text{
	width: 90%;
	height:80rpx;
	margin:30rpx auto;
	display: flex;
	justify-content: center;
	align-items: center;
	vertical-align: middle;
	border-radius: 15rpx;
	background-image:linear-gradient(to right,#feb27a,#ff7d5d);
	
	color:#fff;
	line-height: 40rpx;
	text-align: center;
}
</style>